package iso3.pt.action;

import iso3.pt.dao.PtDAO;
import iso3.pt.model.Alumno;
import iso3.pt.model.Asignatura;

import java.util.Map;
import java.util.Set;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.Preparable;

public class Desmatricular extends ActionSupport implements Preparable{
	private PtDAO dao;
	private String codAsignatura, tipoLogin, userName, password;
	private Alumno alum;
	private Set<Asignatura> listaAsignaturas;
	
	public Set<Asignatura> getListaAsignaturas() {
		return listaAsignaturas;
	}

	public void setListaAsignaturas(Set<Asignatura> listaAsignaturas) {
		this.listaAsignaturas = listaAsignaturas;
	}

	@Override
	public void prepare() throws Exception {
		dao= PtDAO.getInstance();
		
	}
	
	public String execute(){
		Map<String,Object> session=ActionContext.getContext().getSession();
		alum= (Alumno) session.get("alum");
		dao.desmatricular(alum.getDni(), Integer.parseInt(codAsignatura));
		listaAsignaturas= dao.getAsignaturas(alum.getDni());
		tipoLogin= (String)session.get("tipoLogin");
		userName= Integer.toString(alum.getDni());
		password= alum.getPassword();
		return "ok";
		
	}

	public PtDAO getDao() {
		return dao;
	}

	public void setDao(PtDAO dao) {
		this.dao = dao;
	}

	public String getCodAsignatura() {
		return codAsignatura;
	}

	public void setCodAsignatura(String codAsignatura) {
		this.codAsignatura = codAsignatura;
	}

	public String getTipoLogin() {
		return tipoLogin;
	}

	public void setTipoLogin(String tipoLogin) {
		this.tipoLogin = tipoLogin;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Alumno getAlum() {
		return alum;
	}

	public void setAlum(Alumno alum) {
		this.alum = alum;
	}
	
	
	
}
